/*
 *   Copyright 1999-2018 dragonshard.net.
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *        http://www.apache.org/licenses/LICENSE-2.0
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package net.dragonshard.dsf.core.toolkit;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;

/**
 * 对象工具类
 *
 * @author hubin
 */
public class ObjectUtils {

  /**
   * 判断object是否为空,集合会校验size
   */
  public static boolean isNull(Object... objs) {
    for (Object obj : objs) {
      if (ObjectUtils.isEmpty(obj)) {
        return true;
      }
    }
    return false;
  }

  /**
   * 判断object是否不为空,集合会校验size
   */
  public static boolean isNotNull(Object... obj) {
    return !ObjectUtils.isNull(obj);
  }

  /**
   * 对象非空判断
   */
  public static boolean isNotEmpty(Object obj) {
    return !ObjectUtils.isEmpty(obj);
  }

  /**
   * 对象空判断
   */
  public static boolean isEmpty(Object obj) {
    if (obj == null) {
      return true;
    }

    if (obj.getClass().isArray()) {
      return Array.getLength(obj) == 0;
    }
    if (obj instanceof CharSequence) {
      return ((CharSequence) obj).length() == 0;
    }
    if (obj instanceof Collection) {
      return ((Collection<?>) obj).isEmpty();
    }
    if (obj instanceof Map) {
      return ((Map<?, ?>) obj).isEmpty();
    }
    // else
    return false;
  }
}
